package emby.stmt;

import emby.EmbyRuntime;
import emby.expr.Expression;
import emby.expr.Literal;
import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

public class Return extends Statement{

	public static final Return retNull = new Return(Literal.NULL);
	private static final long serialVersionUID = 7801930073678666935L;
	Expression returnVal;
	public Return(Expression exp){
		returnVal = exp;
	}
	@Override
	public Object eval(Scope s) {

		Object retVal = returnVal.eval(s);
		if(EmbyRuntime.echo){
			emby.util.Print.println("Returning "+retVal);
		}
		return retVal;
	}

	public String toString(){
		if( returnVal ==null){
			return "{Return_stmt}";
		}
		return "{Return: "+returnVal+"}";
	}
	
	public void codify(IEmbyCodifier ec){
		ec.ret(returnVal);
	}
}
